﻿#region DaWordsrvstatus
/*----------------------------------------------------------------
// 文件名：DaWordsrvstatus.cs
// 功能描述：类Wordsrvstatus的数据访问层
//
// 
// 创建时间：2009-05-03 DtataAccess template . Ver 5.0.20090413
//
// 修改标识： 
// 修改描述： 
//----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using DocSrv.Model; 


namespace DocSrv.Dal
{
	///可以继承更上层接口,IWordsrvstatus ,数据访问层基类DaBase，
	///DaBase中包含了DbException异常处理静态方法
    public	partial  class DaWordsrvstatus:DaBase<MoWordsrvstatus>
    {	 
		#region SQL const
		internal const string TABLE_COLUMNS=" TR_ID ,RC ,UPDATE_TIME ,DESCRIPTION   ";
		
		internal const string SQL_INSERT="INSERT INTO WORDSRVSTATUS ("+TABLE_COLUMNS+") VALUES (@TrId,@Rc,@UpdateTime,@Description)";
		internal const string SQL_SELECT="SELECT "+TABLE_COLUMNS+" FROM WORDSRVSTATUS  ";
		internal const string SQL_SELECT_ONE=SQL_SELECT+" WHERE TR_ID=@TrId";                              
		
		internal const string SQL_EXIST="SELECT COUNT(*) FROM WORDSRVSTATUS  WHERE TR_ID=@TrId  ";
		internal const string SQL_UPDATE="UPDATE WORDSRVSTATUS SET RC=@Rc, UPDATE_TIME=@UpdateTime, DESCRIPTION=@Description WHERE TR_ID=@TrId";
		
		internal const string SQL_DELETE_DEFAULT = "DELETE FROM WORDSRVSTATUS ";
		internal const string SQL_DELETE="DELETE FROM WORDSRVSTATUS WHERE TR_ID=@TrId";
		
		internal const string SQL_COUNT="SELECT COUNT(*) FROM WordSrvStatus";
		#endregion
		       
		#region Constructor
	 
		/// <summary>
        /// 默认构造函数，使用配置文件中默认的数据库配置。
        /// </summary>
		public DaWordsrvstatus ()
		{ 
			this.db=DatabaseFactory.CreateDatabase();
		}
		/// <summary>
        /// 使用指定的databaseName数据库配置。
        /// </summary>
        /// <param name="databaseName">配置文件中数据库的配置名称。</param>
		public DaWordsrvstatus (string databaseName)
		{ 
            this.db = DatabaseFactory.CreateDatabase(databaseName);
		} 
		
		public DaWordsrvstatus (Database db)
		{ 
            this.db = db;
		} 
		
		#endregion
		
		//以下是CRUD方法，每个方法都有引入外部事务的版本

		#region 构造器模块
		
        protected override MoWordsrvstatus ConstructT()
        {
            return new MoWordsrvstatus();
        }
        #endregion
		
	    
		
		#region Add模块 Helper
		
		///build the command object.It never throw exception.
		protected override  DbCommand ConstructAddCommand(Database db)
		{
			DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);
			 
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString);
			db.AddInParameter(dbCommand,"Rc",DbType.Int32);
			db.AddInParameter(dbCommand,"UpdateTime",DbType.DateTime);
			db.AddInParameter(dbCommand,"Description",DbType.String);
			return dbCommand;
		}		
		protected override DbCommand ConstructAddCommand(Database db,MoWordsrvstatus entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_INSERT);			 
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString,entity.PkId);
			db.AddInParameter(dbCommand,"Rc",DbType.Int32,entity.Rc);
			db.AddInParameter(dbCommand,"UpdateTime",DbType.DateTime,entity.UpdateTime);
			db.AddInParameter(dbCommand,"Description",DbType.String,entity.Description);
			return dbCommand;
		}
		
		protected override DbCommand PopulateAddCommandParameters(Database db,DbCommand addCmd,MoWordsrvstatus entity)
		{
			db.SetParameterValue(addCmd,"TrId",entity.PkId);
			db.SetParameterValue(addCmd,"Rc",entity.Rc);
			db.SetParameterValue(addCmd,"UpdateTime",entity.UpdateTime);
			db.SetParameterValue(addCmd,"Description",entity.Description);
			return addCmd;
		}
		
		protected override DbCommand PopulateAddCommandParameters(Database db,DbCommand addCmd,DataRow row)
		{
			db.SetParameterValue(addCmd,"TrId",row["TrId"]);
			db.SetParameterValue(addCmd,"Rc",row["Rc"]);
			db.SetParameterValue(addCmd,"UpdateTime",row["UpdateTime"]);
			db.SetParameterValue(addCmd,"Description",row["Description"]);
			return addCmd;
		}
		
		#endregion
		    
		#region Update模块 Helper
		
		protected override DbCommand ConstructUpdateCommand(Database db)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_UPDATE);		    
			db.AddInParameter(dbCommand,"Rc",DbType.Int32);
			db.AddInParameter(dbCommand,"UpdateTime",DbType.DateTime);
			db.AddInParameter(dbCommand,"Description",DbType.String);
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString);
			 
			return dbCommand;
		}
		protected override DbCommand ConstructUpdateCommand(Database db,MoWordsrvstatus entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_UPDATE);		    
			db.AddInParameter(dbCommand,"Rc",DbType.Int32,entity.Rc);
			db.AddInParameter(dbCommand,"UpdateTime",DbType.DateTime,entity.UpdateTime);
			db.AddInParameter(dbCommand,"Description",DbType.String,entity.Description);
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString,entity.PkId);
			 
			return dbCommand;
		}
		
		protected override DbCommand PopulateUpdateCommandParameters(Database db,DbCommand updateCmd,MoWordsrvstatus entity)
		{
			db.SetParameterValue(updateCmd,"Rc",entity.Rc);
			db.SetParameterValue(updateCmd,"UpdateTime",entity.UpdateTime);
			db.SetParameterValue(updateCmd,"Description",entity.Description);
			db.SetParameterValue(updateCmd,"TrId",entity.PkId);
			return updateCmd;
		}
		protected override DbCommand PopulateUpdateCommandParameters(Database db,DbCommand updateCmd,DataRow row)
		{
			db.SetParameterValue(updateCmd,"Rc",row["Rc"]);
			db.SetParameterValue(updateCmd,"UpdateTime",row["UpdateTime"]);
			db.SetParameterValue(updateCmd,"Description",row["Description"]);
			db.SetParameterValue(updateCmd,"TrId",row["TrId"]);
			return updateCmd;
		}
		
		protected override void PrepareDataAdapterCommand(Database db,out DbCommand dbInsertCommand,
		                     out DbCommand dbUpdateCommand,out DbCommand dbDeleteCommand)
		{
			dbInsertCommand = db.GetSqlStringCommand(SQL_INSERT);
			#region set insert cmd parameters
			db.AddInParameter(dbInsertCommand, "TrId",DbType.AnsiString, "TR_ID", DataRowVersion.Current);
			db.AddInParameter(dbInsertCommand, "Rc",DbType.Int32, "RC", DataRowVersion.Current);
			db.AddInParameter(dbInsertCommand, "UpdateTime",DbType.DateTime, "UPDATE_TIME", DataRowVersion.Current);
			db.AddInParameter(dbInsertCommand, "Description",DbType.String, "DESCRIPTION", DataRowVersion.Current);
			#endregion
			dbUpdateCommand = db.GetSqlStringCommand(SQL_UPDATE);
			#region Set update cmd value parameters
			db.AddInParameter(dbUpdateCommand, "Rc", DbType.Int32, "RC", DataRowVersion.Current);
			db.AddInParameter(dbUpdateCommand, "UpdateTime", DbType.DateTime, "UPDATE_TIME", DataRowVersion.Current);
			db.AddInParameter(dbUpdateCommand, "Description", DbType.String, "DESCRIPTION", DataRowVersion.Current);
			#endregion
			#region set update cmd pk where parameters
			db.AddInParameter(dbUpdateCommand, "TrId", DbType.AnsiString, "TR_ID", DataRowVersion.Current);
			#endregion			
			dbDeleteCommand = db.GetSqlStringCommand(SQL_DELETE);
			#region set delete cmd pk where parameters
			db.AddInParameter(dbDeleteCommand, "TrId", DbType.AnsiString, "TR_ID", DataRowVersion.Current);
			#endregion
		}
		#endregion	
		
		#region Delete模块 Helper		
		
		protected override DbCommand ConstructDeleteCommand(Database db)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
			 
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString);
			 
			return dbCommand;
		}		
		protected override DbCommand ConstructDeleteCommand(Database db,MoWordsrvstatus entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_DELETE);
			 
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString,entity.PkId);
		 
			return dbCommand;
		}
		
		protected override DbCommand ConstructDeleteCommandForWhere(Database db, string where)
        {
            return db.GetSqlStringCommand(SQL_DELETE_DEFAULT + where);            
        }

        protected override DbCommand PopulateDeleteCommandParameters(Database db, DbCommand deleteCmd, MoWordsrvstatus entity)
        {
			db.SetParameterValue(deleteCmd,"TrId",entity.PkId);
			return deleteCmd;
        }

        protected override DbCommand PopulateDeleteCommandParameters(Database db, DbCommand deleteCmd, DataRow row)
        {
			db.SetParameterValue(deleteCmd,"TrId",row["TrId"]);
			return deleteCmd;
        }      
		
		#endregion helper
		
		#region Query模块 Helper

        protected override DbCommand ConstructQueryCommand(string condition)
        {
            return db.GetSqlStringCommand(SQL_SELECT + condition);
        }

        #endregion
		
		#region GetEntity(s)模块 Helper
        
		protected override DbCommand ConstructSelectOneCommand(Database db,MoWordsrvstatus entity)
		{
			DbCommand dbCommand=db.GetSqlStringCommand(SQL_SELECT_ONE);
			 
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString,entity.PkId);
			return dbCommand;
		}
		
		protected override void PopulateEntityByDataReader(IDataReader reader,ref MoWordsrvstatus entity)
		{
			if (!reader.IsDBNull(0)) entity.PkId = reader.GetString(0);
			if (!reader.IsDBNull(1)) entity.Rc = reader.GetInt32(1);
			if (!reader.IsDBNull(2)) entity.UpdateTime = reader.GetDateTime(2);
			if (!reader.IsDBNull(3)) entity.Description = reader.GetString(3);
		}
		
		

        protected override DbCommand ConstructSelectConditionCommand(Database db, string condition)
        {
            return db.GetSqlStringCommand(SQL_SELECT + condition);
        }
		
		#endregion	
		
		#region Count模块 Helper

        protected override DbCommand ConstructCountCommand(Database db)
        {
            return db.GetSqlStringCommand(SQL_COUNT);
        }

        protected override DbCommand ConstructCountConditionCommand(Database db, string condition)
        {
            return db.GetSqlStringCommand(SQL_COUNT + condition);
        }

		#endregion
		
		#region IsExist模块 Helper

        protected override DbCommand ConstructIsExistCommand(Database db, MoWordsrvstatus entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_EXIST);
			db.AddInParameter(dbCommand,"TrId",DbType.AnsiString,entity.PkId);
			return dbCommand;
        }

		#endregion

		
		
	}
}	
#endregion

